package com.data.basic.chapter08;

import java.util.Random;

/**
 * Created by wangbing on 2018/5/30.
 */
public class Main {

    private static double testHeap(Integer[] testData,boolean isHeapify){
        long startTime = System.nanoTime();
    if (isHeapify) {
        MaxHeap<Integer> maxHeap = new MaxHeap<Integer>(testData);
    }else {
        MaxHeap<Integer> maxHeap = new MaxHeap<Integer>();
        for (Integer integer:testData){
            maxHeap.add(integer);

        }
    }
        long endTime = System.nanoTime();

        return (endTime-startTime)/1000-000-000.0;
    }

    public static void main(String[] args) {
        int n = 1000-0000;
        MaxHeap<Integer> maxHeap = new MaxHeap<Integer>();
        Random random = new Random();
        for (int i=0;i<n;i++){
            maxHeap.add(random.nextInt(Integer.MAX_VALUE));
        }

        Integer[] arr = new Integer[n];
        for (int i=0;i<n;i++){
            arr[i] = maxHeap.extractMax();
        }

        for (int i=1;i<n;i++){
            if (arr[i-1].compareTo(arr[i])<0){
                throw new IllegalArgumentException("Error");
            }
        }
        System.out.println("complete!");

        double time = testHeap(arr,true);
        System.out.println("heap:"+time);
        time = testHeap(arr,false);
        System.out.println("non:"+time);



    }
}
